package qc.module.cms.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qc.common.core.exception.QCPromptException;
import qc.module.cms.dto.link.LinkCategoryDto;
import qc.module.cms.service.LinkCategoryService;

import java.util.List;

/**
 * LinkCategoryController
 *
 * @author QuCheng Tech
 * @create 2023/5/25
 */
@RestController
@RequestMapping("/linkcategory")
public class LinkCategoryController {
    private LinkCategoryService linkCategoryService;

    @Autowired
    public void setLinkCategoryService(LinkCategoryService linkCategoryService) {
        this.linkCategoryService = linkCategoryService;
    }

    //是否为逻辑删除，为true表示逻辑删除--修改记录标记，为false表示物理删除--从数据库表中删除记录
    private static final boolean isLogicDelete = false;

    /**
     * 查询所有链接分类信息，不管状态
     *
     * @return 链接分类集合
     * @author QcCheng Tech
     * @since 2023/5/25
     */
    @RequestMapping(value = "/query", method = {RequestMethod.GET})
    public List<LinkCategoryDto> query() {
        return linkCategoryService.getAll(true);
    }

    /**
     * 获取指定分类信息，不管状态
     *
     * @param id 链接分类ID
     * @return 分类信息
     * @author QcCheng Tech
     * @since 2023/5/25
     */
    @RequestMapping(value = "/get", method = {RequestMethod.GET})
    public LinkCategoryDto getByParam(@RequestParam int id) throws QCPromptException {
        return linkCategoryService.get(id);
    }

    /**
     * 获取指定分类信息，不管状态
     *
     * @param id 链接分类ID
     * @return 分类信息
     * @author QcCheng Tech
     * @since 2023/5/25
     */
    @RequestMapping(value = "/get/{id}", method = {RequestMethod.GET})
    public LinkCategoryDto getByPath(@PathVariable(required = true) int id) throws QCPromptException {
        return linkCategoryService.get(id);
    }

    /**
     * 新增
     *
     * @param dto 链接分类
     * @return 成功返回null
     * @author QcCheng Tech
     * @since 2023/5/25
     */
    @RequestMapping(value = "/add", method = {RequestMethod.POST})
    public String add(@RequestBody LinkCategoryDto dto) {
        return linkCategoryService.add(dto);
    }

    /**
     * 修改
     *
     * @param dto 链接分类
     * @return 成功返回null
     * @author QcCheng Tech
     * @since 2023/5/25
     */
    @RequestMapping(value = "/update", method = {RequestMethod.PUT, RequestMethod.POST})
    public String update(@RequestBody LinkCategoryDto dto) {
        return linkCategoryService.update(dto);
    }

    /**
     * 删除
     *
     * @param id 链接分类ID
     * @return 成功返回null
     * @author QcCheng Tech
     * @since 2023/5/25
     */
    @RequestMapping(value = "/delete", method = {RequestMethod.DELETE})
    public String deleteByParam(@RequestParam int id) throws QCPromptException {
        return linkCategoryService.delete(id, isLogicDelete);
    }

    /**
     * 删除
     *
     * @param id 链接分类ID
     * @return 成功返回null
     * @author QcCheng Tech
     * @since 2023/5/25
     */
    @RequestMapping(value = "/delete/{id}", method = {RequestMethod.DELETE})
    public String deleteByPath(@PathVariable(required = true) int id) throws QCPromptException {
        return linkCategoryService.delete(id, isLogicDelete);
    }
}
